package com.hadoopSpark.application.test;

/*
 * 显示某一个服务详细信息
 */
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.aliyun.configuration.ConfigurationTool;
import com.aliyun.util.String2JsonTool;
import com.certificate.tool.SetTrustStore;
import com.common.constant.Constant;

public class ShowApplicationBaseInfo {

	public static void main(String[] args) throws Exception {

		SSLConnectionSocketFactory sslsf = SetTrustStore.getSSLConnection();

		// httpclient链接
		CloseableHttpClient httpClient = HttpClients.custom()
				.setSSLSocketFactory(sslsf).build();
		CloseableHttpResponse httpResponse = null;
		HttpGet httpGet = null;
		try {
			
			httpGet = new HttpGet(ConfigurationTool.getProperties(Constant.ALIYUN_PROJECTS_URL)+args[0]);

			httpResponse = httpClient.execute(httpGet);

			if (httpResponse.getStatusLine().getStatusCode() == 200) {
				//输出协议，响应码，结果
//				System.out.println(httpResponse.getProtocolVersion() + " "
//						+ httpResponse.getStatusLine().getStatusCode() + " "
//						+ httpResponse.getStatusLine().getReasonPhrase());
				String bodyAsString = EntityUtils.toString(httpResponse.getEntity());
				
				String2JsonTool.printJson(bodyAsString);
//				System.out.println("OK!!!");
			} else {
				
				//输出协议，响应码，结果
				System.out.println(httpResponse.getProtocolVersion() + " "
						+ httpResponse.getStatusLine().getStatusCode() + " "
						+ httpResponse.getStatusLine().getReasonPhrase());
				
				String bodyAsString = EntityUtils.toString(httpResponse
						.getEntity());
				
				String2JsonTool.printJson(bodyAsString);
				
				System.out.println("Something is wrong!!!");
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			httpResponse.close();
			httpClient.close();
		}
	}
}
